<template>
  <div class="chart-container" ref="chartRef"></div>
</template>

<script lang="ts">
export default {
  name: "LineChart",
};
</script>

<script lang="ts" setup>
/*
  1. 下载echarts
    npm i echarts
  2. 引入echarts
    import * as echarts from 'echarts'
  3. 准备具备宽高的DOM容器
  4. 生成图表
    创建echarts实例
    定义图表option
    渲染图表
*/
import * as echarts from "echarts";
import { onMounted, ref } from "vue";

const chartRef = ref();

onMounted(() => {
  const myEcharts = echarts.init(chartRef.value);
  const option = {
    xAxis: {
      show: false,
      min: 0,
      max: 100,
    },
    yAxis: {
      show: false,
      data: ["百分比"],
    },
    tooltip: {},
    series: {
      type: "bar",
      data: [33],
      barWidth: 10, // 柱条宽度
      showBackground: true, // 柱条背景色
      itemStyle: {
        // 柱条样式
        color: "#9acd32",
      },
      label: {
        // 提示文字
        show: true,
        position: "right",
        formatter: "|",
        color: "#9acd32",
      },
    },
    grid: {
      left: 0,
      right: 0,
      top: 0,
      bottom: 0,
    },
  };
  myEcharts.setOption(option);
});
</script>

<style scoped>
.chart-container {
  height: 100%;
}
</style>
